package delegate4j;

import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;

import java.util.concurrent.FutureTask;

@FunctionalInterface
public interface IAsyncCallback extends ICallback {

    default void invoke() throws Exception  {
        throw new DelegatesInvokeException("该接口未实现！");
    }

    void invoke(@NotNull Object sender, @Nullable Object[] data) throws Exception ;

    default FutureTask<Void> invokeAsync(@NotNull Object sender, @Nullable Object[] data) {
        FutureTask<Void> futureTask = new FutureTask<>(() -> {
            invoke(sender, data);
            return null;
        });

        ASYNC_DELEGATE_CALLBACK_THREAD_POOL.submit(futureTask);
        return futureTask;
    }
}
